#include "../pch.h"

namespace BFX
{
REFXMLText::REFXMLText(const UniString& strData, REFXMLDocument* pDoc) :
	REFXMLLinkedNode(pDoc)
{
	m_strData = strData;
}

REFXMLText::~REFXMLText()
{
}

UniString REFXMLText::GetName() const
{
	return GetOwnerDocument()->m_strTextName;
}
UniString REFXMLText::GetLocalName() const
{
	return GetOwnerDocument()->m_strTextName;
}
XMLNodeType REFXMLText::GetNodeType() const
{
	return XMLNodeType_Text;
}
REFXMLNode* REFXMLText::GetParentNode() const
{
	switch (m_pParentNode->GetNodeType())
	{
	case XMLNodeType_Document:
		return NULL;
	case XMLNodeType_Text:
	case XMLNodeType_CDATA:
	case XMLNodeType_Whitespace:
	case XMLNodeType_SignificantWhitespace:
		{
			REFXMLNode* pParent = m_pParentNode->m_pParentNode;
			while (pParent->IsText())
			{
				pParent = pParent->m_pParentNode;
			}
			return pParent;
		}
	default:
		return m_pParentNode;
	}
}

UniString REFXMLText::GetValue() const
{
	return m_strData;
}
void REFXMLText::SetValue(const UniString& str)
{
	m_strData = str;
	// TODO: Unspecified attribute???
}

UniString REFXMLText::GetInnerText() const
{
	return GetValue();
}
void REFXMLText::SetInnerText(const UniString& str)
{
	SetValue(str);
}

void REFXMLText::WriteTo(REFXMLWriter* w) const
{
	w->WriteString(GetValue());
}

void REFXMLText::WriteContentTo(REFXMLWriter* w) const
{
	// Intentionally do nothing
}

bool REFXMLText::IsText() const
{
	return true;
}

REFXMLNode* REFXMLText::GetPreviousText() const
{
	if (m_pParentNode->IsText())
		return m_pParentNode;
	return NULL;
}

// Gets the length of the data, in characters.
int REFXMLText::GetLength() const
{
	return m_strData.GetLength();
}

}	//	namespace BFX
